-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix trimming analyzer missing diagnostics for method calls in field access expressions #123040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…s for method calls Co-authored-by: sbomer <[email protected]>
Co-authored-by: sbomer <[email protected]>
|
@copilot fix error: '/__w/1/s/src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Support/DynamicallyAccessedMembersAttribute.cs'.\n/__w/1/s/artifacts/bin/ILLink.testcases/linker_tests/DataFlow/GetInterfaceDataFlow/GetInterfaceDataFlow.cs(197,55): error CS1061: 'Type[]' does not contain a definition for 'First' and no accessible extension method 'First' accepting a first argument of type 'Type[]' could be found (are you missing a using directive or an assembly reference?)\n/__w/1/s/artifacts/bin/ILLink.testcases/linker_tests/DataFlow/GetInterfaceDataFlow/GetInterfaceDataFlow.cs(209,55): error CS1061: 'Type[]' does not contain a definition for 'First' and no accessible extension method 'First' accepting a first argument of type 'Type[]' could be found (are you missing a using directive or an assembly reference?)\n/__w/1/s/artifacts/bin/ILLink.testcases/linker_tests/DataFlow/GetInterfaceDataFlow/GetInterfaceDataFlow.cs(219,55): error CS1061: 'Type[]' does not contain a definition for 'First' and no accessible extension method 'First' accepting a first argument of type 'Type[]' could be found (are you missing a using directive or an assembly reference?)\n)\n---- System.Exception : Roslyn compilation |
… [0] Co-authored-by: sbomer <[email protected]>
Fixed in 8b353ad. Replaced |
|
@copilot fix this error: Unexpected warning found: ILLink: Trim analysis warning IL2075: Mono.Linker.Tests.Cases.DataFlow.GetInterfaceDataFlow.GetInterfaceMap_DataFlow.TestDirectCall(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. Be sure to run this test before committing. |
…id IL2075 warnings Co-authored-by: sbomer <[email protected]>
Fixed in 025264e. Replaced |
Fix for Type.GetInterfaceMap Trimming Analyzer Issue (#117849)
Problem
The trimming analyzer fails to report diagnostics when method calls are used in field access expressions. For example,
type.GetInterfaceMap(@interface).TargetMethodsdoes not warn, whiletype.GetInterfaceMap(@interface)correctly reports IL2072.Root cause:
TrimAnalysisVisitor.VisitFieldReferencedoes not visit the field's instance operation before processing the field itself.Fix: Visit the instance before processing the field, consistent with how other visitor methods handle instances (property references, event references).
Changes
Visit(fieldRef.Instance, state);at the start ofVisitFieldReference()typeof(TestType)instead ofo.GetType()to avoid unrelated IL2075 warnings[0]instead of LINQ for test framework compatibilityTesting
Impact
This is a targeted fix that only affects field reference analysis. The change ensures that:
Original prompt
Type.GetInterfaceMap(Type)is treated oddly by the trimming analyzers #108114💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.